package com.hnx.admin.aurora.system.controller;

import com.hnx.admin.aurora.annotation.Log;
import com.hnx.admin.aurora.enums.BusinessType;
import com.hnx.admin.aurora.system.domain.param.dept.form.DeptForm;
import com.hnx.admin.aurora.system.domain.param.dept.query.DeptQuery;
import com.hnx.admin.aurora.system.service.DeptService;
import com.hnx.admin.aurora.utils.UUIDUtil;
import com.hnx.admin.aurora.web.json.ResultJson;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/*
创建人： 倔强的头发
创建时间：2025/7/2
功能描述:

*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/system/dept")
public class SysDeptController {
    private final DeptService deptService;
    @PreAuthorize("@auth.hasPermi('system:dept:list')")
    @GetMapping("/list")
    public ResultJson list(DeptQuery dept)
    {
        return deptService.selectList(dept);
    }
    /**
     * 新增部门
     */
    @PreAuthorize("@auth.hasPermi('system:dept:add')")
    @Log(title = "部门管理", businessType = BusinessType.INSERT)
    @PostMapping
    public ResultJson add(@Validated @RequestBody DeptForm dept)
    {
        dept.setDeptId(UUIDUtil.getUUID());
        return deptService.insertDept(dept);
    }
    /**
     * 根据部门编号获取详细信息
     */
    @PreAuthorize("@auth.hasPermi('system:dept:query')")
    @GetMapping(value = "/{deptId}")
    public ResultJson getInfo(@PathVariable String deptId)
    {
        return deptService.selectDeptById(deptId);
    }
    /**
     * 查询部门列表（排除节点）
     */
    @PreAuthorize("@auth.hasPermi('system:dept:list')")
    @GetMapping("/list/exclude/{deptId}")
    public ResultJson excludeChild(@PathVariable(value = "deptId", required = false) String deptId)
    {
        return deptService.selectList(new DeptQuery());
    }
    /**
     * 删除部门
     */
    @PreAuthorize("@auth.hasPermi('system:dept:remove')")
    @Log(title = "部门管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{deptId}")
    public ResultJson remove(@PathVariable String deptId)
    {
        return deptService.deleteDeptById(deptId);
    }
    /**
     * 修改部门
     */
    @PreAuthorize("@auth.hasPermi('system:dept:edit')")
    @Log(title = "部门管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResultJson edit(@Validated @RequestBody DeptForm dept)
    {
        return deptService.updateDept(dept);
    }
}
